import 'package:analyzer/dart/element/element.dart';
import '../hb_router_annotation.dart';
import 'hb_clazz_template.dart';
import 'hb_page_info.dart';
import 'package:source_gen/source_gen.dart';
import 'hb_annotation_item.dart';
import 'package:build/build.dart';

class HBRouteGenerator extends GeneratorForAnnotation<HBRoute> {

  @override
  generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) {
    final projectName = annotation.peek("projectName")?.stringValue;
    return hbTplRender(pages: HBPageInfo.instance.pages, projectName: projectName);
  }
}

class HBRoutePageGenerator extends GeneratorForAnnotation<HBRoutePage> {
  @override
  generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) {
    HBPageInfo.instance.pages.add(
        HBAnnotationItem()
            ..clazzName = element.name
            ..refer=buildStep.inputId.uri.path
            ..paramKey = annotation.peek("paramKey")?.stringValue
            ..routeAnnotation = annotation.peek("routeAnnotation")?.stringValue
    );
    return null;
  }
}
